﻿using AopCommon;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using System;
using System.Reactive;

namespace AopAvalonia.ViewModels
{
    public class MainViewModel : ViewModelBase
    {
        private static MainViewModel m_Instance = new MainViewModel();

        public static MainViewModel Instance => m_Instance;

        private MainViewModel()
        {
            MessageBus.Current.Listen< PromptMsg>().Subscribe(OnPromptMsg);
        }

        private void OnPromptMsg(PromptMsg msg)
        {
            this.Greeting += "\r\n" + msg.Content;
        }

        [Reactive] public string Greeting { get; set; } = "Welcome to Avalonia!";

        public ReactiveCommand<Unit, Unit> TestCommand => CreateOrGet(Test);

        public ReactiveCommand<bool, Unit> TestCommand2 => CreateOrGet<bool>(Test2);

        public ReactiveCommand<Unit, bool> TestCommand3 => CreateOrGet<bool>(Test3);

        public ReactiveCommand<bool, bool> TestCommand4 => CreateOrGet<bool,bool>(Test4);

        public ReactiveCommand<Unit, int> TestCommand5 => ReactiveCommand.Create<int>(Test5);

        public void Test()
        {

        }

        public void Test2(bool value)
        {

        }

        public bool Test3()
        {
            return true;
        }

        public bool Test4(bool value)
        {
            return !value;
        }

        [Logging]

        public int Test5()
        {
            throw new System.Exception("测试异常");
            return 30;
        }
    }
}